package com.xiaoh.leetcode.easy;

import java.util.Arrays;

/**
 * @author xiaoh
 * @ClassName Shuffle_1470
 * @Description 给你一个数组 nums ，数组中有 2n 个元素，按 [x1,x2,...,xn,y1,y2,...,yn] 的格式排列。
 * @Date 2020/8/20 10:40
 * @Version 1.0
 */
public class Shuffle_1470 {

    public static int[] shuffle(int[] nums, int n) {
        if (nums.length == 2 * n) {
            int[] result = new int[2 * n];
            for (int i = 0; i < nums.length; i++) {
                if (i == 0 && i % 2 == 0) {
                    result[i] = nums[i];
                    result[i + 1] = nums[n + i];
                } else if (i % 2 == 0){
                    result[i] = nums[i - 1];
                    result[i + 1] = nums[n + i - 1];
                }
            }
            return result;
        }
        return null;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,4,3,2,1};
        int n = 4;
        int[] result = shuffle(nums, n);
        System.out.println(Arrays.toString(result));
    }
}
